<?php
/**
 * Created by PhpStorm.
 * User: g
 * Date: 2018/3/14
 * Time: 13:08
 */

namespace app\index\controller;

use think\Controller;
use think\Session;
use think\Request;
use think\View;
use think\Db;
use think\Validate;
use app\index\validate\Valid;

class Wdwljc extends Common
{
    /**
     * 所有网点物料检查
     */
    public function allnetwlcheck(){
        $wdbh = $this->request->param('wdbh');
        $wdmc = $this->request->param('wdmc');
        $hbr_xm = $this->request->param('hbr_xm');
        $start = $this->request->param('start');
        $end = $this->request->param('end');
        $this->assign([
            'wdbh'=>$wdbh,
            'wdmc'=>$wdmc,
            'hbr_xm'=>$hbr_xm,
            'start'=>$start,
            'end'=>$end,
        ]);
        $where = [];
        if($wdbh){
            $where['wdbm'] = ['like',"%{$wdbh}%"];
        }
        if($wdmc){
            $where['wdmc'] = ['like',"%{$wdmc}%"];
        }
        if($hbr_xm){
            $where['hbr_xm'] = ['like',"%{$hbr_xm}%"];
        }
        if($start&&$end){
            $where['hbrq'] = ['between',[$start,$end]];
        }elseif($start){
            $where['hbrq'] = ['>',$start];
        }elseif($end){
            $where['hbrq'] = ['<',$end];
        }

        $count = db('yd_wljc')->where($where)->count();
        $data = db('yd_wljc')->where($where)->paginate(10,$count);
        $page = $data->render();
        $data = $data->items();
        foreach($data as $k=>$v){

            $data[$k] = $v;
        }
        $this->assign('data',$data);
        $this->assign('page',$page);
        return $this->fetch();
    }
    /**
     * 所属网点物料检查
     */
    public function tonetwlcheck(){
        $wdbh = $this->request->param('wdbh');
        $wdmc = $this->request->param('wdmc');
        $hbr_xm = $this->request->param('hbr_xm');
        $start = $this->request->param('start');
        $end = $this->request->param('end');
        $this->assign([
            'wdbh'=>$wdbh,
            'wdmc'=>$wdmc,
            'hbr_xm'=>$hbr_xm,
            'start'=>$start,
            'end'=>$end,
        ]);
        $where = [];
        $where['net_id'] = ['exp',"in(select id from cg_net where stuff like '%\"".session('employee_id')."\%')"];
        if($wdbh){
            $where['wdbm'] = ['like',"%{$wdbh}%"];
        }
        if($wdmc){
            $where['wdmc'] = ['like',"%{$wdmc}%"];
        }
        if($hbr_xm){
            $where['hbr_xm'] = ['like',"%{$hbr_xm}%"];
        }
        if($start&&$end){
            $where['hbrq'] = ['between',[$start,$end]];
        }elseif($start){
            $where['hbrq'] = ['>',$start];
        }elseif($end){
            $where['hbrq'] = ['<',$end];
        }

        $count = db('yd_wljc')->where($where)->count();
        $data = db('yd_wljc')->where($where)->paginate(10,$count);
        $page = $data->render();
        $data = $data->items();
        foreach($data as $k=>$v){

            $data[$k] = $v;
        }
        $this->assign('data',$data);
        $this->assign('page',$page);
        return $this->fetch();
    }
}